package com.judian.smart.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.judian.smart.R;
import com.judian.smart.holder.SceneViewHolder;
import com.judian.smart.interfaces.OnListItemClickListener;
import com.judian.smart.model.Mode;

import java.util.List;

/**
 * author: Peter
 * date: 2019/08/09 星期五 14:25
 * desc:
 */
public class SceneListAdapter extends RecyclerView.Adapter<SceneViewHolder> {
    private Context mContext;
    private List<Mode> mData;
    private OnListItemClickListener<Mode> listener;

    public SceneListAdapter(Context context, List<Mode> data) {
        mContext = context;
        mData = data;
    }

    public void setListener(OnListItemClickListener<Mode> listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    public SceneViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_mode, parent, false);
        view.getLayoutParams().height = 448 / 4 - 3;//设置列表显示三行  -3表示加上间隔
        return new SceneViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull SceneViewHolder holder, final int position) {
        holder.modeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.setOnItemClick(mData.get(position), position);
            }
        });
        holder.modeName.setText(mData.get(position).getModeName());
        holder.modeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.setOnItemClick(mData.get(position), position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }
}
